<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/header.jsp" %>
<script>	
var flag="";//事件标识
var scripts = [null, null];
$('.page-content-area').ace_ajax('loadScripts', scripts, function() {


		initDetail();
	});
 
    function initDetail(){
    	var sendFlag = $("#sendFlag").val();
    	if(sendFlag==1){
    		//新增
    		$("#btnAModify").hide();
    		$("#btnADelete").hide();
    		$("#btnASave").show();
    		$("#btnACancle").hide();
    	}else if(sendFlag==2){
    		//查询
    		$("#btnAModify").show();
        	$("#btnADelete").hide();
        	$("#btnASave").hide();
        	$("#btnACancle").hide();
    		disabledAll("dictDetailForm");
    	}
    }
    
    //保存信息
	function save(){ 
		enabledAll("dictDetailForm");
		
		$("#dictDetailForm").validate({
		    errorElement: 'div',
		    errorClass: 'help-block',
		    focusInvalid: false,
		    rules: {
		    	dictDesc: {
		          required: true
		       }
		    },
		    messages: {
		    	dictDesc: {
		           required: "字典描述不能为空！"
		        }      
		    },
		
		    highlight: function (e) {
		        $(e).closest('.form-group').removeClass('has-info').addClass('has-error');
		    },
		    success: function (e) {
		        $(e).closest('.form-group').removeClass('has-error').addClass('has-info');
		        $(e).remove();
		    },
		    errorPlacement: function (error, element) {
		        error.insertAfter(element.parent());
		    }
		});	
		if ($("#dictDetailForm").valid() == false) {
				return;
		}	
		
    	//必输项校验
		if(checkRequiredFields()){
			var sendFlag = $("#sendFlag").val();
	    	var urlVal = "${ctx}/dict/save.do";
	    	if(sendFlag==3){
	    	    //修改路径
	    	    urlVal = "${ctx}/dict/update.do";
	    	}
			saveDictInfo(urlVal);
		}
	}
	//异步保存转授权信息
	function saveDictInfo(urlVal){
		enabledAll("dictDetailForm");
		var params = {
				"dictType":$("#dictType_detail").val(),
				"dictDesc":$("#dictDesc_detail").val(),
				"remarks":$("#remark_detail").val()
		};
		 $.ajax({
	        	async : false,
		    	url: urlVal,
		    	type:"post",
		    	data: $.param(params),
		    	dataType:"json", 
		    	success: function(data){				    					    		
				   	if(data[0]=="ok"){
				   		alert(data[1]);
					   	initDetail();
					   	
					    $("#dictDetailIframe").dialog("close");
					   	$("#dictListIframe").show();
					   	$("#dictListIframe").load("${ctx}/dict/list.do?temp="+new Date().getTime(),$("#dict_info_form").serialize());
				   	}else{
				   		alert(data[1]);
				   	}
		    	}
	       	}); 
	}
	//必输项校验
	function checkRequiredFields(){
		var dictDesc = $("#dictDesc_detail").val();
		var remark = $("#remark_detail").val();
		
		if(dictDesc==null ||dictDesc==''){
		   alert("字典描述不能为空！");
		   return false;
		}
		
		return true;
	}
	
 function modify(){
	$("#btnAModify").hide();
	$("#btnADelete").hide();
	$("#btnASave").show();
	$("#btnACancle").show();
	$("#sendFlag").val("3");
	enabledAll("dictDetailForm");
 }
//取消修改
 function cancle(){
 	var iscancle=window.confirm("确定取消修改？");
 	if(iscancle==true){
 		document.dictDetailForm.reset();
 		disabledAll("dictDetailForm");
 		$("#btnAModify").show();
 		$("#btnADelete").hide();
 		$("#btnASave").hide();
 		$("#btnACancle").hide();
 	}
 	else{
 		return;
 	}
 }
 
</script>
	<div class="col-xs-12">
	 <form name="dictDetailForm" id="dictDetailForm" class="form-horizontal" role="form">
	   <input type="hidden" id="sendFlag" name="sendFlag" value="${sendFlag}" />
	    <input type="hidden" id="dictType_detail" name="dictType_detail" value="${sysDictType.dictType}" />
		
		       	<div class="row" >
		       <div class="form-group ">
		       		<label class="col-sm-3 control-label no-padding-left" for="dictDesc">字典类型描述<font color="red">*</font></label>
					<div class="col-sm-9">
					  <div class="clearfix">
					  	<input type="text" id="dictDesc_detail" class="col-xs-10 col-sm-9" name="dictDesc"  value="${sysDictType.dictDesc}" maxlength="60"/>
		              </div>
		            </div>
		       </div> 
		</div>
		<div class="row" >
		       <div class="form-group ">
		       		<label class="col-sm-3 control-label no-padding-left" for="remark_detail">备注</label>
					<div class="col-sm-8">
					  <div class="clearfix">
						<textarea class="limited form-control can-modify" id="remark_detail" name="remarks" maxlength="160">${sysDictType.remarks}</textarea>
		      		  </div>
		      		</div>
		       </div>
		       
		</div>
	</form>
	</div>

<div id="chooseMemberInfo"></div>
